package com.shelpe.services.simbasync.service.simbaproxy;

import java.util.Date;
import java.util.List;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;

import lombok.Data;

@FeignClient(name="${simbaproxy.serviceID}", url="${simbaproxy.url}")
@RequestMapping(value = "/simba")
public interface CategoryProxy {
	
	/**
	 * 获取类目信息
	 * 0表示请求所有顶级类目的信息，这时可以忽略第二个参数，1表示获取给定的类目id的详细信息，2表示获取给定类目id的所有子类目的详细信息
	 * */
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.insight.catsinfo.get")
	public CategoryListRespone getCategory(@RequestHeader("tenantID") long userId, @RequestParam("type") int type, @RequestParam("category_id_list") String categoryIds);
	
	@RequestMapping(method = RequestMethod.GET, value = "/taobao.simba.insight.catsdata.get")
	public InsightCatDataResponse getInsightData(@RequestHeader("tenantID") long userId, @RequestParam("category_id_list") String catIds, @RequestParam("start_date") String startDate, @RequestParam("end_date") String endDate);
	
	
	@Data
	public static class CategoryListRespone extends SimbaProxyBaseDto{		
		@JsonProperty("simba_insight_catsinfo_get_response")
		private CategoryListRes res;
	}
	
	@Data
	public static class CategoryListRes{		
		@JsonProperty("category_info_list")
		private CategoryList dataList;
	}
	
	@Data
	public class CategoryList {
		@JsonProperty("insight_category_info_d_t_o")
		private List<CategoryDto> categories;
	}
	
	@Data
	public static class CategoryDto{
		@JsonProperty("cat_id")
		private int categoryID;
		@JsonProperty("cat_name")
		private String name;
		@JsonProperty("cat_level")
		private int level;
		@JsonProperty("parent_cat_id")
		private int parentID;
		@JsonProperty("cat_path_id")
		private String categoryIDs;
		@JsonProperty("cat_path_name")
		private String names;
		@JsonProperty("last_sync_time")
		@JsonFormat(shape=Shape.STRING, pattern="yyyy-MM-dd HH:mm:ss")
		private Date wordsUpdated;
	}
	
	/**************************************************/
	
	@Data
	public static class InsightCatDataResponse extends SimbaProxyBaseDto {
		
		@JsonProperty("simba_insight_catsdata_get_response")
		private CatDataListRes res;
	}
	
	@Data
	public static class CatDataListRes {
		
		@JsonProperty("cat_data_list")
		private CatDataList dataList;
	}
	
	@Data
	public static class CatDataList {
		
		@JsonProperty("insight_category_data_d_t_o")
		private List<InsightCatDataDto> dto;
	}
	
	@Data
	public static class InsightCatDataDto {
		
		private Long impression;
		private Long click;
		private Long cost;
		@JsonProperty("directtransaction")
		private Long directTransaction; //": 52357127,
        @JsonProperty("indirecttransaction")
        private Long indirectTransaction; //": 20853489,
		@JsonProperty("directtransactionshipping")
		private Long directTransactionShipping; //": 5415,
		@JsonProperty("indirecttransactionshipping")
		private Long indirectTransactionShipping;  //": 1782,
		@JsonProperty("favitemtotal")
		private Long favItemTotal; //": 50323,
		@JsonProperty("favshoptotal")
		private Long favShopTotal; //": 6458,
		@JsonProperty("transactionshippingtotal")
		private Long transactionShippingTotal; //": 7119,
		@JsonProperty("transactiontotal")
		private Long transactionTotal; //": 72343545
		@JsonProperty("favtotal")
		private Long favTotal; //": 56386,
		private Long competition; //": 167518,
		private String ctr;  //": "0.4",
		private String cpc;  // ": "35.96",
		private String roi; // ": "0.76",
		private String coverage; //: "0.22",
		@JsonProperty("cat_id")
		private Integer catId;
		@JsonProperty("cat_name")
		private String catName;
	}

}
